package cloudUser.customer;

import cloudEntity.utils.ResultUtils;
import cn.hutool.json.JSONUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @program: Smart School
 * @ClassName CustomerAccessDeniedHandler
 * @description: 自定义 403 页面
 * @author: 陈智博
 * @create: 2025-04-10 11:13
 * @Version 1.0
 **/
@Component
public class CustomerAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResultUtils<String> failed = ResultUtils.failed(403,"没有权限","null");
        response.setContentType("application/json;charset=utf-8");
        String jsonStr = JSONUtil.toJsonStr(failed);
        response.getWriter().write(jsonStr);
    }
}
